package cn.vetech.sync.elasticsearch.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class DateUtil {
    /**
     * 将DateTime转换为Date
     *
     * @param dateOrDateTime
     * @param <T>
     * @return
     */
    public static <T> Date toDate(T dateOrDateTime) {
        if (dateOrDateTime.getClass() == LocalDateTime.class) {
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = (LocalDateTime) dateOrDateTime;
            ZonedDateTime zdt = localDateTime.atZone(zoneId);
            return Date.from(zdt.toInstant());
        }
        return null;
    }
}
